//引入样式
import "../../assets/css/normalize.less";
import "../../assets/css/reset.less";
import "../../assets/css/property.less";
import "../../assets/css/basic.less";

import "./course.less";

//引入dom
import { $ } from "../../utils/dom";

//引入nav
import { showBottomNav, showTopNav } from "../../utils/nav";

//引入请求接口
import { getCourseList } from "../../api/course";

/**
 * 顶部导航
 */
showTopNav("sportcourse");

/**
 * 底部导航
 */
showBottomNav("sport");

/**
 * 获取课程列表
 */
const getCouse = async () => {
  let res = await getCourseList();
  let { errno, data } = res.data;
  if (errno === 0) {
    console.log(data);
    //新课程
    let newCourse = data.shift();
    $("#newImg").src = "http://fitness.h5.itsource.cn:3701" + newCourse.imgurl;
    $("#newName").textContent = newCourse.name;
    $("#newDesc").textContent = newCourse.desc;

    //老课程
    let html = "";
    data.forEach((v) => {
      html += `
            <a href="./course_detail.html#${v.courseId}" class="course">
                <img src="http://fitness.h5.itsource.cn:3701${v.imgurl}" alt="">
                <p class="bold">${v.name}</p>
                <p class="desc">${v.desc}</p>
            </a>
        `;
    });
    $("#oldCourse").innerHTML += html;
  }
};
getCouse();
